import java.lang.reflect.Array;
import java.util.*;

/**
 * @User: vitobo
 * @Date: 2024-06-13
 * @Description: ArrayList的使用
 *
 * 1. 当调用不带参数的构造方法的时候,只有第一个add的时候,才会分配大小为10的内存
 *      当放第11个元素的时候, 采用1.5倍的扩容方式
 *
 *
 *
 */

class Student implements Comparable<Student>{
    private String name;
    private int age;
    private double score;

    public Student(int age, String name, double score){
        this.age = age;
        this.name = name;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return (int)(this.score - o.score);
    }
}

public class Test {
    public static ArrayList<Character> func(String str1, String str2){
        ArrayList<Character> arrayList = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")){
                arrayList.add(ch);
            }
        }
        return arrayList;
    }
    public static List<Character> func2(String str1, String str2){
        List<Character> arrayList = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")) {
                arrayList.add(ch);
            }
        }
        return arrayList;
    }
    public static void main(String[] args) {
        List<Character> ret = func("welcome to xian", "come");
        for (int i = 0; i < ret.size(); i++) {
            System.out.print(ret.get(i));
        }
        System.out.println();
    }

    public static void main3(String[] args) {
        ArrayList<Student> arrayList = new ArrayList<>();
        arrayList.add(new Student(15, "小许", 80.5));
        arrayList.add(new Student(18, "小高", 95.3));
        arrayList.add(new Student(17, "小温", 68.8));
        for(Student s : arrayList){
            System.out.println(s);
        }
        System.out.println("=================");
        Collections.sort(arrayList);
        for(Student s : arrayList){
            System.out.println(s);
        }
    }

    public static void main2(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        arrayList1.add(3);
        arrayList1.add(4);
        arrayList1.add(5);

        List<Integer> list = arrayList1.subList(1,3);
        System.out.println(list);

        System.out.println("========================");
        list.set(0,99);
        System.out.println(arrayList1);  // 1 99 3 4 5
        System.out.println(list);        // 99 3
    }

    public static void main1(String[] args) {
        // 初始化
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        System.out.println(arrayList1);

        ArrayList<Integer> arrayList2 = new ArrayList<>(20);
        arrayList2.add(2);
        arrayList2.add(3);
        arrayList2.add(4);
        System.out.println(arrayList2);

        LinkedList<Integer> arrayList3 = new LinkedList<>();
        ArrayList<Integer> arrayList4 = new ArrayList<>(arrayList3);

    }
}
